<?php
session_start();

if (!$_SESSION['loggedin']) {
    // User not logged in, redirect to login page
    echo "<script language='javascript'>window.location='index.php'</script>";
}
if ($_SESSION['loggedin'] && $_SESSION['accounttype'] == 'professor') {
?>
    <html>    
        <head>
            <link rel="stylesheet" href="css/style.css" type="text/css" id="" media="print, projection, screen" />
            <script type="text/javascript" src="script/jquery-latest.js"></script>
            <script type="text/javascript" src="script/jquery.tablesorter.js"></script>
            <script type="text/javascript" src="script/jquery.tablesorter.pager.js"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    // call the tablesorter plugin
                    $("table").tablesorter({
                        // sort on the first column and third column, order asc
                        sortList: [[0,0]],
                        headers: {
                            // assign the secound column (we start counting zero)
                            6: {
                                // disable it by setting the property sorter to false
                                sorter: false
                            }
                        }
                    });
                });

                function confirmLogout()
                {
                    var agree=confirm("Are you sure you want to Logout?");
                    if (agree)
                        return true ;
                    else
                        return false ;
                }
            </script>

            <title>TUP Professor Management</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>

        <body style=" height:100%; width: 100%; background-image: url(image/wall6.jpg);">

            <div id="container" style="height:auto; width: 100%;">

                <div style="background-image: url(image/wall12.jpg); height: 110px; width: auto; ">
                </div>


                <div align="center" style="background-image: url(image/wall11.jpg);  height: 74px; width: auto;">

                    <div align="center" style=" height: 4px; width: auto;"></div>
                    <div align="center" style=" height: 22px; width: auto;">
                        <a href="AMMSelectSection.php"><b>[ Select Section ]</b></a>&nbsp;&nbsp;
                    </div>
                    <div align="center" style=" height: 4px; width: auto;"></div>
                    <div align="center" style=" height: 22px; width: auto;">


                    </div>

                    <div  align="left" style="padding-left: 4%; height: 18px; width: 46%;float:left;"><?php echo "<aa class=\"smallw\"><b>Welcome " . $_SESSION['fname'] . ", Last login: " . $_SESSION['lastlogin'] . "</b></aa>"; ?>
                    </div>
                    <div align="right" style="padding-right: 4%; height: 18px; width: 46%;float:left;"><bb>|</bb>
                        <a class="small" href="ProfEditProfile.php"><b>Edit Profile</b></a>
                        <bb>|</bb>
                        <a onclick="return confirmLogout()" class="small" href="Logout.php"><b>Logout</b></a>
                        <bb>|</bb></div>

                </div>

                <div align="center" style="padding-left: 4%;  float:left; width: 96%; background-image: url(image/wall6.jpg);">


                    <h4><?php echo $_SESSION['lfmname']; ?></h4>
                    <h2>Sections Handled</h2>

                <?php
                $prof = $_POST['prof'];
                echo $prof;

                include 'DBLibrary/config.php';
                include 'DBLibrary/openDB.php';
                $_SESSION['codesecsemyear'] = null;
                mysql_select_db($dbname);
                $idno = $_SESSION['idno'];

                $sql = "SELECT codesecsemyear, teacher, coursetitle, coursecode, description, section, minnumstud, manumstud, totalstud, room, semester, year, starttime, endtime, units, idno,fname, mname, lname FROM coursetable c LEFT JOIN user u ON c.teacher=u.idno WHERE c.teacher='" . $idno . "'";

                //-run the query against the mysql query function
                $result = mysql_query($sql);
                ?>
                <table  border="0" id="myTable" class="tablesorter" style="width: 95%;" align="center">
                    <thead><tr>
                            <th>Course Code</th>
                            <th>Course Section</th>
                            <th>Professor</th>
                            <th>Min Students</th>
                            <th>Max Students</th>
                            <th>Total Students</th>
                            <th>Select</th>
                        </tr></thead><tbody>

<?php
                while ($row = mysql_fetch_array($result)) {
                    $ctr++;
                    //if()
                    //echo "<tr>" . "<td>" . $ctr . "</td>";<th>No.</th>
                    echo "<tr><td>" . $row['coursecode'] . "</td>";
                    echo "<td>" . $row['section'] . "</td>";

                    if ($row['teacher'] != "blank")
                        echo "<td>" . $row['lname'] . ",&nbsp;" . $row['fname'] . "&nbsp;" . $row['mname'] . "</td>";
                    else
                        echo "<td>" . $row['teacher'] . "</td>";

                    echo "<td>" . $row['minnumstud'] . "</td>";
                    echo "<td>" . $row['manumstud'] . "</td>";
                    echo "<td>" . $row['totalstud'] . "</td>";




                    echo "<form name=\"add\" method=\"post\" action=\"AMMViewAttendance.php\">
                                    <td style=\"vertical-align: middle;\"><input type=\"submit\" name=\"Select\" value=\"Select\"/><input type=\"text\" name=\"prof\" size=\"1\" value=\"" . $prof . "\" style=\"visibility:hidden;\"/>
                               <input type=\"text\" name=\"codesecsemyear\" size=\"1\" value=\"" . $row['codesecsemyear'] . "\" style=\"visibility:hidden;\"/></td></tr>";
                    echo "</form>";
                }
?> </tbody></table> <?php
?>

            </div>

            <div id="footer" style="background-image: url(image/wall11.jpg);clear:both;text-align:center; height: 26px; width:auto;">
                <div align="center" style=" height: 4px; width: auto;"></div>
                <bb class ="small">Copyright &#169; 2011</bb>
            </div>


        </div>

    </body>
</html>
<?php
                    } else if ($_SESSION['loggedin'] && $_SESSION['accounttype'] == 'admin') {
                        echo "<script language='javascript'>window.location='UMMViewUser.php'</script>";
                    } else if ($_SESSION['loggedin'] && $_SESSION['accounttype'] == 'registrar') {
                        echo "<script language='javascript'>window.location='SMMViewStud.php'</script>";
                    }
?>